#lang racket
;==============================================================================;
;=================================== MAIN.RKT =================================;
;Version : 1.0.0
;Rôle : Créer le contexte de l'animation et la lancer à l'aide d'un bigbang.
;==============================================================================;




;==============================================================================;
;============== PARTIE 1 - Variables globales et autres définitions ===========;
;==============================================================================;

;---------------------------- 1.0 - importations ------------------------------;
(require "monde.rkt" "image.rkt" "note.rkt" "partition.rkt")
(require rsound rsound/piano-tones)
(require 2htdp/image 2htdp/universe)

;----------------------- 1.1 - Définition des images --------------------------;
(define balle1 (new Balle% (posY 50) (posX 50) (rayon 20) (couleur "blue")))
(define balle2 (new Balle% (posY 50) (posX 150) (rayon 30) (couleur "green")))
(define balle3 (new Balle% (posY 50) (posX 250) (rayon 20) (couleur "yellow")))
(define balle4 (new Balle% (posY 50) (posX 350) (rayon 40) (couleur "grey")))
(define balle5 (new Balle% (posY 50) (posX 450) (rayon 45) (couleur "yellow")))
(define balle6 (new Balle% (posY 50) (posX 550) (rayon 10) (couleur "grey")))



(define balles (list balle1 balle2 balle3 balle4 balle5 balle6))


;----------------------- 1.2 - Définition des notes ---------------------------;
(define la-piano-noire (new note%))
(define boum (rs-read "./sounds/boum.wav"))
(define pak (rs-read "./sounds/pak.wav"))

;-------------------- 1.3 - Définition des partitions -------------------------;
(define partition1 
  (new partition% 
       (notes 
        (list
         (new note% (son (piano-tone 76)) (type "noire")) ; Reloop sur P1
         (new note% (son (piano-tone 83)) (type "blanche")) ; Reloop sur P2
         (new note% (son boum) (type "noire") (animation-class 'null) (image-class 'null))
         (new note% (son boum) (type "noire") (animation-class 'null) (image-class 'null))
         (new note% (son boum) (type "noire") (animation-class 'null) (image-class 'null))
         (new note% (son boum) (type "blanche") (animation-class 'null) (image-class 'null))
         ))))



(define partition2 
  (new partition% 
       (notes 
        (list
         (new note% (son boum) (type "noire") (animation-class 'null) (image-class 'null))
         (new note% (son pak) (type "croche") (animation-class 'null) (image-class 'null))
         (new note% (son pak) (type "croche") (animation-class 'null) (image-class 'null))
         (new note% (son boum) (type "noire") (animation-class 'null) (image-class 'null))
         (new note% (son pak) (type "croche") (animation-class 'null) (image-class 'null))
         (new note% (son pak) (type "croche") (animation-class 'null) (image-class 'null))
         (new note% (son boum) (type "noire") (animation-class 'null) (image-class 'null))
         (new note% (son pak) (type "croche") (animation-class 'null) (image-class 'null))
         (new note% (son pak) (type "croche") (animation-class 'null) (image-class 'null))
         (new note% (son boum) (type "noire") (animation-class 'null) (image-class 'null))
         (new note% (son pak) (type "croche") (animation-class 'null) (image-class 'null))
         (new note% (son pak) (type "croche") (animation-class 'null) (image-class 'null))
         (new note% (son boum) (type "noire") (animation-class 'null) (image-class 'null))
         (new note% (son pak) (type "croche") (animation-class 'null) (image-class 'null))
         (new note% (son pak) (type "croche") (animation-class 'null) (image-class 'null))
         (new note% (son boum) (type "noire") (animation-class 'null) (image-class 'null))
         (new note% (son pak) (type "croche") (animation-class 'null) (image-class 'null))
         (new note% (son pak) (type "croche") (animation-class 'null) (image-class 'null))
         ))
       ))

(define partition3 
  (new partition% 
       (notes 
        (list
         (new note% (son (piano-tone 81)) (type "noire")) ; P1
         (new note% (son (piano-tone 84)) (type "croche"))
         (new note% (son (piano-tone 83)) (type "croche4"))
         (new note% (son (piano-tone 81)) (type "croche4"))
         (new note% (son (piano-tone 83)) (type "croche"))
         (new note% (son (piano-tone 88)) (type "croche"))
         (new note% (son (piano-tone 76)) (type "noire"))
         (new note% (son (piano-tone 81)) (type "noire"))
         (new note% (son (piano-tone 84)) (type "croche"))
         (new note% (son (piano-tone 83)) (type "croche4"))
         (new note% (son (piano-tone 81)) (type "croche4"))
         (new note% (son (piano-tone 80)) (type "noire")) ;/P1
         (new note% (son (piano-tone 76)) (type "noire"))
         (new note% (son (piano-tone 81)) (type "noire")) ; P2
         (new note% (son (piano-tone 84)) (type "croche"))
         (new note% (son (piano-tone 83)) (type "croche4"))
         (new note% (son (piano-tone 81)) (type "croche4"))
         (new note% (son (piano-tone 83)) (type "croche"))
         (new note% (son (piano-tone 88)) (type "croche"))
         (new note% (son (piano-tone 76)) (type "noire"))
         (new note% (son (piano-tone 77)) (type "croche4"))
         (new note% (son (piano-tone 79)) (type "croche4"))
         (new note% (son (piano-tone 81)) (type "croche4"))
         (new note% (son (piano-tone 83)) (type "croche4"))
         (new note% (son (piano-tone 84)) (type "croche"))
         (new note% (son (piano-tone 83)) (type "croche"))
         (new note% (son (piano-tone 81)) (type "noire")) ; /P2
         (new note% (son (piano-tone 81)) (type "noire"))
         (new note% (son (piano-tone 88)) (type "croche")) ; P3
         (new note% (son (piano-tone 88)) (type "croche"))
         (new note% (son (piano-tone 88)) (type "croche"))
         (new note% (son (piano-tone 88)) (type "croche"))
         (new note% (son (piano-tone 89)) (type "croche4"))
         (new note% (son (piano-tone 88)) (type "croche4"))
         (new note% (son (piano-tone 88)) (type "croche4"))
         (new note% (son (piano-tone 86)) (type "croche4"))
         (new note% (son (piano-tone 86)) (type "noire"))
         (new note% (son (piano-tone 86)) (type "croche"))
         (new note% (son (piano-tone 86)) (type "croche"))
         (new note% (son (piano-tone 86)) (type "croche"))
         (new note% (son (piano-tone 86)) (type "croche"))
         (new note% (son (piano-tone 88)) (type "croche4"))
         (new note% (son (piano-tone 86)) (type "croche4"))
         (new note% (son (piano-tone 86)) (type "croche4"))
         (new note% (son (piano-tone 84)) (type "croche4"))
         (new note% (son (piano-tone 84)) (type "noire"))
         (new note% (son (piano-tone 84)) (type "croche"))
         (new note% (son (piano-tone 84)) (type "croche"))
         (new note% (son (piano-tone 84)) (type "croche"))
         (new note% (son (piano-tone 83)) (type "croche4"))
         (new note% (son (piano-tone 84)) (type "croche4"))
         (new note% (son (piano-tone 86)) (type "croche"))
         (new note% (son (piano-tone 81)) (type "croche"))
         (new note% (son (piano-tone 86)) (type "noire"))
         (new note% (son (piano-tone 84)) (type "croche"))
         (new note% (son (piano-tone 83)) (type "croche4"))
         (new note% (son (piano-tone 81)) (type "croche4"))
         (new note% (son (piano-tone 79)) (type "noire")) ; /P3
         (new note% (son (piano-tone 76)) (type "noire")) ; Reloop sur P1
         (new note% (son (piano-tone 83)) (type "blanche")) ; Reloop sur P2
         ))))


;------------- 1.4 - Définition des autres éléments importants ----------------;

(define _ps (make-pstream))
(define (p n) (pstream-play _ps n)) 
;j'initialise le pstream ici pour pouvoir tester des son au niveau de la console
;et tester mon animations sans provoquer de conflits

;==============================================================================;
;========================== PARTIE 2 - L'animation ============================;
;==============================================================================;
(define (animation)
  (define HEIGHT 400) ;Hauteur de la scene
  (define WIDTH 800) ;Largeur de la scene
  (define SCENE (rectangle WIDTH HEIGHT 'solid "magenta"))
  (define monde (new monde% 
                     (partitions (list partition1 partition2 partition3))
                     (images balles)
                     (ps _ps)))
  ;Initialisation des temps d'attente initiaux des partitions
  (send partition2 set-temps-attente
        (+ 0 (send monde deduire-temps-total partition1)))
  (send partition3 set-temps-attente
        (+ 0 (send monde deduire-temps-total partition1)))
  
  
  ;------------------------------ SUIVANT -------------------------------------;
  (define (suivant monde)
    (send monde lire-partitions)
    monde)
  
  
  ;----------------------------- DESSINER -------------------------------------;
  (define (dessiner monde)
    (define ecran SCENE)
    (for [(img (in-list (send monde get-images)))]
      (set! ecran
            (underlay/xy ecran
                         (send img getPosX) (send img getPosY)
                         (send img getImage))))
    ecran)
  
  
  ;----------------------------- FINISHED? ------------------------------------;
  (define (finished? monde)
    (send monde is-over?))
  
  
  ;------------------------------ BIG-BANG ------------------------------------;
  (big-bang monde
            (on-tick suivant 1/48)
            (on-draw dessiner)
            (stop-when finished?)))










;==============================================================================;
;=========================== PARTIE 3 - Les tests =============================;
;==============================================================================;

